<template>
  <div>
    <!-- 录入按钮 -->
    <div class="toAdd">
      <!-- 一行两列 -->
      <el-row>
        <el-col :span="20" style="height:32px"></el-col>
        <el-col :span="4" style="text-align:right">
          <el-button type="primary">录入</el-button>
        </el-col>
      </el-row>

    </div>
    <!-- 表格数据 -->
    <div class="table">
      <el-table :data="engData" style="width: 100%">
        <el-table-column type="index" :index="1" label="序号" width="80px">
        </el-table-column>
        <el-table-column prop="serial_number" label="编号" width="180px">
        </el-table-column>
        <el-table-column prop="name" label="名称" width="380px">
        </el-table-column>
        <el-table-column prop="type" label="工程类型">
        </el-table-column>
        <el-table-column prop="status" label="状态">
          <template v-slot="scope">
            <div>
              <el-tag v-if="scope.row.status==='监测中'" type="success">监测中</el-tag>
              <el-tag v-else type="warning">未绑定</el-tag>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center">
          <template v-slot="scope">
            <div>
              <el-button type="text">修改</el-button>
              <el-button type="text">绑定</el-button>
              <el-button type="text" v-if="scope.row.status==='监测中'">结束</el-button>
              <el-button type="text" v-if="scope.row.status==='未绑定'" disabled>结束</el-button>
              <el-button type="text" v-if="scope.row.status==='未绑定'">删除</el-button>
              <el-button type="text" v-if="scope.row.status==='监测中'" disabled>删除</el-button>
            </div>
          </template>

        </el-table-column>
      </el-table>
    </div>
    <!-- 分页按钮 -->
    <div class="page" style="margin-top:15px;text-align:right">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="params.page"
        :page-sizes="[2, 5, 10, 20]" :page-size="params.pageSize" layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        hide-on-single-page
        >
      </el-pagination>
    </div>

  </div>
</template>
<script>
// 引入get方法
import { get } from '@/utils/request'
export default {
  // 数据模型 vue变量
  data() {
    return {
      // 工程数据
      engData: [],
      // 分页数据
      params: {
        page: 1,
        pageSize: 5
      },
      // 总条数
      total: 0
    }
  },
  methods: {
    // 获取工程数据
    async getEngData() {
      let res = await get('/engineer/pageQuery', this.params);
      console.log(res, '获取响应');
      this.engData = res.data.list;
      this.total = res.data.total;
    },
    // 数据条数发生变化函数
    handleSizeChange(pageSize ) {
      // console.log(pageSize,'条数');
      // 当条数发生改变 重新请求工程数据
      // params.pageSize --->2 
      this.params.pageSize = pageSize;
      // 重新请求工程数据
      this.getEngData();
    },
    // 页码发生改变函数
    handleCurrentChange(page) {
      // console.log(page,'当前页码');
      this.params.page = page;
      this.getEngData();
    }


  },
  created() {
    this.getEngData()
  }
}
</script>